package com.abe.signature;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.tencent.smtt.sdk.TbsReaderView;

public class FileBrowseActivity extends Activity implements TbsReaderView.ReaderCallback{

    LinearLayout layout;
    TbsReaderView readerView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_file_browse);
        readerView = new TbsReaderView(this, this);
        layout = findViewById(R.id.item_reader_root_view);
        layout.addView(readerView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            onBackPressed();
            return;
        }
        String filePath = extras.getString("filePath");
        if (TextUtils.isEmpty(filePath)) {
            Toast.makeText(this, "文件路径为空", Toast.LENGTH_SHORT).show();
            onBackPressed();
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putString("filePath", filePath);
        bundle.putString("tempPath", Environment.getExternalStorageDirectory().getPath());
        String mFileName = filePath.substring(filePath.lastIndexOf(".") + 1);
        boolean result = readerView.preOpen(mFileName, false);
        if (result) {
            readerView.openFile(bundle);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        readerView.onStop();
    }

    @Override
    public void onCallBackAction(Integer integer, Object o, Object o1) {

    }
}